import React, { Component } from "react";

// 高阶组件本质：是一个函数，需要传入一个组件，并且返回一个新组件
const hoc = (Comp, n) => {
  return class extends Component {
    state = {
      count: n,
    };

    add = () => {
      this.setState({
        count: this.state.count + 1,
      });
    };

    render() {
      return (
        <>
          {/* <Comp count="1" /> */}
          {/* <footer>@千锋教育</footer> */}

          {/* {...this.props}表示将所有接受的props，全部往下传 */}
          <Comp count={this.state.count} add={this.add} {...this.props} />
        </>
      );
    }
  };
};

class App extends Component {
  state = {};
  render() {
    console.log(this.props);
    return (
      <div>
        <h2>hoc高阶组件</h2>
      </div>
    );
  }
}

// const App2 = hoc(App);

export default hoc(App, 10);
